package service

import (
	"app-webapi/comm/g"
	"app-webapi/entity"
	"errors"
	"gorm.io/gorm"
)

func GetUserinfo(username string) (user *entity.Userinfo) {
	first := g.Db.Where(&entity.Userinfo{Username: username}).First(&user)
	// 检查 ErrRecordNotFound 错误
	if errors.Is(first.Error, gorm.ErrRecordNotFound) {
		g.Logger.Error("查询用户信息异常：", first.Error)
		return nil
	}
	return
}

func GetUserinfoById(id int64) (user *entity.Userinfo) {
	first := g.Db.First(&user, id)
	// 检查 ErrRecordNotFound 错误
	if errors.Is(first.Error, gorm.ErrRecordNotFound) {
		g.Logger.Error("查询用户信息异常：", first.Error)
		return nil
	}
	return
}
